﻿<%@ Page Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true" CodeBehind="PromotionFatherList.aspx.cs"
    Inherits="PromotionEngine.PromotionFatherList" Title="Promotion Engine - List of Promotions" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        var oCompany = {};
        var isInsert = false;
        var companyData;
        var gird;
        var record = 0;
       
        function onChange(arg) {
            var selectedRows = this.select();
            var selectedDataItems = [];
            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = this.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem);
            }
            if (selectedDataItems.length > 0) {
                parent.LoadFatherPromotionCode(selectedDataItems[0].PromotionCode, selectedDataItems[0].PromotionName, selectedDataItems[0].PromotionID);
                
            }
        }
        
        $(document).ready(function () {
            grid = $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "PromotionHeader.aspx/GetPromotionHeaders",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            timeout: 30000
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "destroy") {
                                return { docEntry: data.DocEntry };
                            }
                        },
                        type: "odata", //Important!!!!
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d.Data;
                                return data;
                            }
                        },
                        total: "d.Count",
                        model: {
                            id: "PromotionID",
                            fields: {
                                PromotionID: { type: "string", validation: { required: true} },
                                CompanyCode: { type: "string", validation: { required: true} },
                                PromotionCode: { type: "string", validation: { required: true} },
                                PromotionName: { type: "string", validation: { required: true} },
                                FatherPromotionCode: { type: "string", validation: { required: true} },
                                PromotionType: { type: "string", validation: { required: true} },
                                FromDate: { type: "date", validation: { required: true} },
                                ToDate: { type: "date", validation: { required: true} },
                                FromTime: { type: "date", validation: { required: true} },
                                ToTime: { type: "date", validation: { required: true} },
                                IsActive: { type: "boolean", validation: { required: true} },
                                IsOpional: { type: "boolean", validation: { required: true} },
                                FromAmount: { type: "number", validation: { required: true} },
                                ToAmount: { type: "number", validation: { required: true} },
                                FromQuantity: { type: "number", validation: { required: true} },
                                ToQuantity: { type: "number", validation: { required: true} },
                                DiscountType: { type: "number", validation: { required: true} },
                                DiscountValue: { type: "number", validation: { required: true} },
                                MaxCountApply: { type: "number", validation: { required: true} },
                                Monday: { type: "boolean", validation: { required: true} },
                                MondayStart: { type: "date", validation: { required: true} },
                                MondayEnd: { type: "date", validation: { required: true} },
                                Tuesday: { type: "boolean", validation: { required: true} },
                                TuesdayStart: { type: "date", validation: { required: true} },
                                TuesdayEnd: { type: "date", validation: { required: true} },
                                Wednesday: { type: "boolean", validation: { required: true} },
                                WednesdayStart: { type: "date", validation: { required: true} },
                                WednesdayEnd: { type: "date", validation: { required: true} },
                                Thursday: { type: "boolean", validation: { required: true} },
                                ThursdayStart: { type: "date", validation: { required: true} },
                                ThursdayEnd: { type: "date", validation: { required: true} },
                                Friday: { type: "boolean", validation: { required: true} },
                                FridayStart: { type: "date", validation: { required: true} },
                                FridayEnd: { type: "date", validation: { required: true} },
                                Saturday: { type: "boolean", validation: { required: true} },
                                SaturdayStart: { type: "date", validation: { required: true} },
                                SaturdayEnd: { type: "date", validation: { required: true} },
                                Sunday: { type: "boolean", validation: { required: true} },
                                SundayStart: { type: "date", validation: { required: true} },
                                SundayEnd: { type: "date", validation: { required: true} },
                                CreatedUserID: { type: "string", validation: { required: true} },
                                CreatedDate: { type: "string", validation: { required: true} },
                                BudgetAmount: { type: "number", validation: { required: true} },
                                TargetRevenue: { type: "number", validation: { required: true} }
                            }
                        }
                    }
                },
                change: onChange,
                sortable: true,
                pageable: true,
                pageable: {
                    pageSize: 20,
                    refresh: true
                },
                filterable: true,
                reorderable: true,
                resizable: true,
                selectable: "row",
                height: 530,
                excel: {
                    fileName: "Promotion Header.xlsx",
                    filterable: true,
                    allPages: true
                },
                batch: true,
                columns: [
                            {
                            title: "No.",
                            template: "#= ++record #",
                            width: 60
                          },
                            { field: "PromotionID", title: "Promotion ID", width: 90, attributes: { style: "text-align:centrer;"} , hidden: true},
                            { field: "CompanyCode", title: "CompanyCode", width: 200, hidden: true },
                            { field: "PromotionCode", title: "PromotionCode", width: 160},
                            { field: "PromotionName", title: "PromotionName", width: 500 },
                            { field: "FatherPromotionCode", title: "FatherPromotionCode", width: 100, hidden: true },
                            { field: "PromotionType", title: "PromotionType", hidden: true },
                            { field: "FromDate", title: "FromDate", template: '#= kendo.toString(FromDate, "dd/MM/yyyy") #', hidden: true },
                            { field: "ToDate", title: "ToDate", template: '#= kendo.toString(ToDate, "dd/MM/yyyy") #', hidden: true },
                            { field: "FromTime", title: "FromTime", template: '#= kendo.toString(FromTime, "hh:mm:tt") #', hidden: true },
                            { field: "ToTime", title: "ToTime", template: '#= kendo.toString(ToTime, "hh:mm:tt") #', hidden: true },
                            { field: "IsActive", title: "IsActive", width: 150, hidden: true },
                            { field: "IsOpional", title: "IsOpional", width: 100, hidden: true },
                            { field: "FromAmount", title: "FromAmount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} , hidden: true},
                            { field: "ToAmount", title: "ToAmount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} , hidden: true},
                            { field: "FromQuantity", title: "FromQuantity", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} , hidden: true},
                            { field: "ToQuantity", title: "ToQuantity", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;"} , hidden: true},
                            { field: "DiscountType", title: "DiscountType", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;" }, hidden: true },
                            { field: "DiscountValue", title: "DiscountValue", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;" }, hidden: true },
                            { field: "MaxCountApply", title: "MaxCountApply", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;" }, hidden: true },
                            { field: "Monday", title: "Monday", width: 100, hidden: true },
                            { field: "MondayStart", title: "MondayStart", width: 100, template: '#= kendo.toString(MondayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "MondayEnd", title: "MondayEnd", width: 100, template: '#= kendo.toString(MondayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "Tuesday", title: "Tuesday", width: 100, hidden: true },
                            { field: "TuesdayStart", title: "TuesdayStart", width: 100, template: '#= kendo.toString(TuesdayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "TuesdayEnd", title: "TuesdayEnd", width: 100, template: '#= kendo.toString(TuesdayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "Wednesday", title: "Wednesday", width: 100, hidden: true },
                            { field: "WednesdayStart", title: "WednesdayStart", width: 100, template: '#= kendo.toString(WednesdayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "WednesdayEnd", title: "WednesdayEnd", width: 100, template: '#= kendo.toString(WednesdayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "Thursday", title: "Thursday", width: 100, hidden: true },
                            { field: "ThursdayStart", title: "ThursdayStart", width: 100, template: '#= kendo.toString(ThursdayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "ThursdayEnd", title: "ThursdayEnd", width: 100, template: '#= kendo.toString(ThursdayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "Friday", title: "Friday", width: 100, hidden: true },
                            { field: "FridayStart", title: "FridayStart", width: 100, template: '#= kendo.toString(FridayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "FridayEnd", title: "FridayEnd", width: 100, template: '#= kendo.toString(FridayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "Saturday", title: "Saturday", width: 100, hidden: true },
                            { field: "SaturdayStart", title: "SaturdayStart", width: 100, template: '#= kendo.toString(SaturdayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "SaturdayEnd", title: "SaturdayEnd", width: 100, template: '#= kendo.toString(SaturdayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "Sunday", title: "Sunday", width: 100, hidden: true },
                            { field: "SundayStart", title: "SundayStart", width: 100, template: '#= kendo.toString(SundayStart, "dd/MM/yyyy") #', hidden: true },
                            { field: "SundayEnd", title: "SundayEnd", width: 100, template: '#= kendo.toString(SundayEnd, "dd/MM/yyyy") #', hidden: true },
                            { field: "CreatedUserID", title: "CreatedUserID", width: 100, hidden: true },
                            { field: "CreatedDate", title: "CreatedDate", width: 100, hidden: true },
                            { field: "BudgetAmount", title: "BudgetAmount", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;" }, hidden: true },
                            { field: "TargetRevenue", title: "TargetRevenue", width: 100, format: "{0:n}", type: "number", attributes: { style: "text-align:right;" }, hidden: true }//,
                            ],
                editable: {
                    mode: "popup"
                },
                dataBinding: function() {
                    record = (this.dataSource.page() -1) * this.dataSource.pageSize();
                  },
                edit: function (e) {
                   
                }
            }).data("kendoGrid");
        });
    </script>
    <div style="position: absolute; z-index: 0; margin-right: 8px; width: 99%;">
        <div id="grid">
        </div>
    </div>
</asp:Content>
